<?php

namespace App\Models\Gameserver;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Lang;

/**
 * App\Models\Gameserver\Player
 *
 * @property int $id
 * @property string $name
 * @property int $account_id
 * @property string $account_name
 * @property int $exp
 * @property int $recoverexp
 * @property float $x
 * @property float $y
 * @property float $z
 * @property int $heading
 * @property string $world_id
 * @property int $world_owner
 * @property string $gender
 * @property string $race
 * @property string $player_class
 * @property string|null $creation_date
 * @property string|null $deletion_date
 * @property string|null $last_online
 * @property bool $cube_expands
 * @property bool $advanced_stigma_slot_size
 * @property bool $warehouse_size
 * @property bool $mailbox_letters
 * @property int $title_id
 * @property int $bonus_title_id
 * @property int $dp
 * @property bool $soul_sickness
 * @property int $reposte_energy
 * @property int $goldenstar_energy
 * @property int $growth_energy
 * @property int $bg_points
 * @property bool $online
 * @property string|null $note
 * @property int $mentor_flag_time
 * @property int $initial_gamestats
 * @property float $last_transfer_time
 * @property int $fatigue
 * @property int $fatigueRecover
 * @property int $fatigueReset
 * @property int $stamps
 * @property string|null $last_stamp
 * @property int $rewarded_pass
 * @property int $joinRequestLegionId
 * @property string $joinRequestState
 * @property int $frenzy_points Upgrade Arcade FrenzyPoints
 * @property int $frenzy_count
 * @property int $show_inventory
 * @property string|null $bonus_buff_time
 * @property string $bonus_type
 * @property int $wardrobe_size
 * @property bool $is_highdaeva
 * @property int $creativity_point
 * @property int $creativity_step
 * @property int $wardrobe_slot
 * @property int $luna_consume_count
 * @property int $muni_keys
 * @property int $luna_consume
 * @property int $toc_floor
 * @property int $minion_skill_points
 * @property-read \App\Models\Gameserver\LegionMember $memberOfALegion
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player legion()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player online()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereAccountId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereAccountName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereAdvancedStigmaSlotSize($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereBgPoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereBonusBuffTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereBonusTitleId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereBonusType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereCreationDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereCreativityPoint($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereCreativityStep($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereCubeExpands($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereDeletionDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereDp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereExp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereFatigue($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereFatigueRecover($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereFatigueReset($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereFrenzyCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereFrenzyPoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereGender($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereGoldenstarEnergy($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereGrowthEnergy($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereHeading($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereInitialGamestats($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereIsHighdaeva($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereJoinRequestLegionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereJoinRequestState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereLastOnline($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereLastStamp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereLastTransferTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereLunaConsume($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereLunaConsumeCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereMailboxLetters($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereMentorFlagTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereMinionSkillPoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereMuniKeys($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereNote($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereOnline($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player wherePlayerClass($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereRace($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereRecoverexp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereReposteEnergy($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereRewardedPass($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereShowInventory($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereSoulSickness($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereStamps($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereTitleId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereTocFloor($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereWardrobeSize($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereWardrobeSlot($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereWarehouseSize($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereWorldId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereWorldOwner($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereX($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereY($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gameserver\Player whereZ($value)
 * @mixin \Eloquent
 */
class Player extends Model
{

    protected $table = 'players';
    protected $connection = 'gameserver';
    protected $fillable = ['account_name'];
    public $timestamps = false;

    /**
     * @param Builder $query
     * @return Builder
     */
    public function scopeOnline(Builder $query)
    {
        return $query->where('online', 1);
    }

    /**
     * Return legion
     * @param  [type] $query [description]
     * @return [type]        [description]
     */
    public function scopeLegion($query)
    {
        return $query->with(['memberOfALegion' => function ($query2) {
            return $query2->with(['legion']);
        }]);
    }

    /**
     * Return player level base on the exp
     *
     * @param integer $value 2314763
     *
     * @return integer 19
     */
    public function getExpAttribute($value)
    {
        $expMapper = Lang::get('aion.exp');

        foreach ($expMapper as $xp => $level) {
            if ($value <= $xp) {
                return $level;
                break;
            }
        }
    }

    /**
     * Return name of the map
     *
     * @param  integer $value 110010000
     *
     * @return string Sanctum
     */
    public function getWorldIdAttribute($value)
    {
        $mapMapper = Lang::get('aion.map');

        foreach ($mapMapper as $id => $name) {
            if ($value == $id) {
                return $name;
                break;
            }
        }
    }

    /**
     * Return Legion Members
     */
    public function memberOfALegion()
    {
        return $this->belongsTo('App\Models\Gameserver\LegionMember', 'id', 'player_id');
    }
}
